import request from '@/utils/request'

/**
 * 获取Spu列表
 * @param {*} page:当前页
 * @param {*} limit:每页显示数量
 * @param {*} cate3Id:三级分类Id
 * @returns
 */
export const reqSpuList = (page, limit, cate3Id) => {
  return request({
    url: `/admin/product/${page}/${limit}`,
    method: 'get',
    params: {
      category3Id: cate3Id
    }
  })
}

/**
 * 根据SpuId获取Spu信息
 * @param {*} id:SpuId
 * @returns
 */
export const reqGetSpuInfoById = (spuId) => {
  return request({
    url: `/admin/product/getSpuById/${spuId}`,
    method: 'get'
  })
}

/**
 * 获取品牌列表
 * @returns
 */
export const reqGetTradeMark = () => {
  return request({
    url: '/admin/product/baseTrademark/getTrademarkList',
    method: 'get'
  })
}

/**
 * 根据SpuId获取Spu图片列表
 * @param {*} id
 * @returns
 */
export const reqSpuImageList = (spuId) => {
  return request({
    url: `/admin/product/spuImageList/${spuId}`,
    method: 'get'
  })
}

/**
 * 获取平台销售属性
 * @returns
 */
export const reqBaseSaleAttrList = () => {
  return request({
    url: '/admin/product/baseSaleAttrList',
    method: 'get'
  })
}

/**
 * 添加|修改 spu信息
 * @param {*} spuInfo
 * @returns
 */
export const reqAddOrUpdateSpu = (spuInfo) => {
  if (spuInfo.id) {
    // 如果传递的spuInfo有id属性，则为修改
    return request({
      url: '/admin/product/updateSpuInfo',
      method: 'post',
      data: spuInfo
    })
  } else {
    // 没有id属性为添加
    return request({
      url: '/admin/product/saveSpuInfo',
      method: 'post',
      data: spuInfo
    })
  }
}

/**
 * 根据SpuId删除Spu
 * @param {*} spuId
 * @returns
 */
export const reqDeleteSpu = (spuId) => {
  return request({
    url: `/admin/product/deleteSpu/${spuId}`,
    method: 'delete'
  })
}

/**
 * 根据spuId获取其sku信息
 * @param {*} spuId
 * @returns
 */
export const reqSkuList = (spuId) => {
  return request({
    url: `/admin/product/findBySpuId/${spuId}`,
    method: 'get'
  })
}
